<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Document</title>
  </head>
  <body>
    <div></div>
    <script>
      var div = document.querySelector('div');
      div.dataset.index = '2';
      div.setAttribute('data-name', 'andy');
    </script>
  </body>
</html>